<template>
	<view class="main">
		<view class="month">
			<view class="title">
				筛选
			</view>
			<picker class="time" mode="selector" fields="month" @change="selectType" :range="type">
				<view>{{type[typeIndex]}}</view>
			</picker>
		</view>
		<view class="content">
			<view class="list" v-for="item in list" @click="detail">
				<view class="content">
					<view class="name">
						收益来源：
					</view>
					<view class="time">
						{{item.product_name}}
					</view>
				</view>
				<view class="content">
					<view class="name">
						开通时间：
					</view>
					<view class="time">
						{{item.createtime | time}}
					</view>
				</view>
				<view class="content">
					<view class="name">
						收益类型：
					</view>
					<view class="time">
						{{item.level=='2'?'直接推广':'间接推广'}}
					</view>
				</view>
				<view class="content">
					<view class="name">
						开通时间：
					</view>
					<view class="time">
						{{item.createtime | time}}
					</view>
				</view>
				<view class="content">
					<view class="name">
						来源人
					</view>
					<view class="time">
						{{item.nickname}}
					</view>

				</view>
				<view class="content">
					<view class="name" style="color:#656565">
						金额：
					</view>
					<view class="time" style="color: #d4237a;">
						+{{item.money}}
					</view>
				</view>
				<!-- <view class="look">
					查看详情
				</view> -->
			</view>
		</view>
		<u-empty v-if="list.length==0" text="暂无数据" mode="list"></u-empty>
	</view>
</template>

<script>
	import {
		profitDetail
	} from "@/api/index.js"
	export default {
		data() {
			return {
				time: '',
				type: ['全部', '直接推广', '间接推广'],
				typeIndex: 0,
				list: [],
				page: 1,
				size: 10,
				level: ''
			};
		},
		filters: {
			time(time) {
				let date = new Date(time);
				let year = date.getFullYear();
				let month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份从0开始，需要加1，并且补零
				let day = ('0' + date.getDate()).slice(-2);
				let hours = ('0' + date.getHours()).slice(-2);
				let minutes = ('0' + date.getMinutes()).slice(-2);
				let seconds = ('0' + date.getSeconds()).slice(-2);

				// 拼接成最终的时间字符串
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			}
		},
		mounted() {
			var currentDate = new Date();
			var currentYear = currentDate.getFullYear();
			var currentMonth = currentDate.getMonth() + 1; // 月份从0开始，所以要加1
			if (currentMonth < 10) {
				currentMonth = "0" + currentMonth
			}
			this.time = currentYear + "-" + currentMonth
			this.getDetail()
		},
		methods: {
			//获取收益明细
			getDetail() {
				let params = {
					level: this.level,
					page: this.page,
					page_size: 10,
				}
				profitDetail(params).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data.list)
						uni.stopPullDownRefresh();
					}
				})
			},
			enablePullDownRefresh() {
				this.page++
				this.getMyCustomer()
			},
			selectType(e) {
				console.log(e)
				this.typeIndex = e.detail.value
				if (e.detail.value == 0) {
					this.level = ''
				} else if (e.detail.value == 1) {
					this.level = 2
				} else {
					this.level = 3
				}
				this.page = 1
				this.list = []
				this.getDetail()
			},
			detail() {
				// uni.navigateTo({
				// 	url: "/pages/wallet/monthDetail"
				// })
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 20rpx 40rpx;
	}

	.list {
		background-color: #fff;
		margin-bottom: 40rpx;
		padding: 26rpx;
		color: #656565;
		border-radius: 20rpx;

		.content {
			font-size: 28rpx;
			display: flex;
			align-items: center;


			.name {
				width: 160rpx;
			}
		}

		.look {
			border: 1px solid #3B81F3;
			text-align: center;
			padding: 8rpx 12rpx;
			border-radius: 10rpx;
			color: #3B81F3;
			font-size: 24rpx;
		}
	}

	.bill {
		background-color: #3B81F3;
		padding: 20rpx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;

		.item {
			flex: 1;
			color: #fff;
			font-size: 28rpx;
			text-align: center;

			.title {
				font-size: 28rpx;
			}

			.number {
				font-size: 32rpx;
			}
		}



		.item:first-child {
			border-right: 1px solid #fff;
		}
	}

	.month {
		background-color: #fff;
		padding: 26rpx;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		margin-bottom: 20rpx;

		.time {
			flex: 1;
			text-align: right;
		}
	}
</style>